<template>
	<view class="bar-fixed" :style="{background: navigationBarStyle.background}">
		<view class="status-line" :style="{height: lineHeight}"></view>
		<view class="bar-line">
			<view class="bar-line container-in">
				<view class="bar-font bar-content" v-if="!custom">
					<view class="icon-fanhui bar-back" :style="{color: navigationBarStyle.iconColor}" @click="$navigateBack('1', 'navigateBack')"
					 v-if="showBack">
						<image style="width: 56rpx;height: 52rpx;" src="../../../static/nav_back_black.png" mode=""></image>
					</view>
					<view class="leftIcon flex_r_between" v-if="leftIcon.isShow">
						<image @click="$linkTo(leftIcon.url1)" style="width: 30rpx;height: 30rpx;" src="../static/homeImg/icon/nav_search_black@2x.png" mode=""></image>
						<image  @click="$linkTo(leftIcon.url2)" style="width: 32rpx;height: 32rpx;" src="../static/homeImg/icon/nav_favorite_black@2x.png" mode=""></image>
					</view>
					<view class="bar-title" :style="{color: navigationBarStyle.fontColor,'font-weight':navigationBarStyle.fontWeight}">{{navigationBarStyle.iconText}}</view>
				</view>
				<view class="bar-font container-in" v-else>
					<slot></slot>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			custom: {
				type: Boolean,
				default: false
			}, //自定义头部，否则沿用原生的头部样式
			navigationBarStyle: {
				type: Object,
				default: function() {
					return {
						background: '#FFFFFF',
						fontColor: '#000000',
						iconColor: '#000000',
						fontWeight:'',
						iconText: '一米一粉' //导航栏文字
					}
				}
			}, //原生头部自定义样式
			showBack: {
				type: Boolean,
				default: true
			}, //是否显示回退图标，默认显示
			leftIcon:{
				type: Object,
				default: function() {
					return {
						isShow:false,
					}
				}
			}
		},
		data() {
			return {
				lineHeight: '' //状态栏高度
			};
		},
		mounted() {
			const systemInfo = uni.getSystemInfoSync();
			// px转换到rpx的比例
			let pxToRpxScale = 750 / systemInfo.windowWidth;
			let systems = {
				ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
				navigationHeight: 44 * pxToRpxScale, // 导航栏的高度
				ktxWindowWidth: systemInfo.windowWidth * pxToRpxScale, // window的宽度
				ktxWindowHeight: systemInfo.windowHeight * pxToRpxScale, // window的高度
				ktxScreentHeight: systemInfo.screenHeight * pxToRpxScale, // 屏幕的高度
			}
			// 底部tabBar的高度
			systems.tabBarHeight = systems.ktxScreentHeight - systems.ktxStatusHeight - systems.navigationHeight - systems.ktxWindowHeight // 底部tabBar的高度
			this.lineHeight = systems.ktxStatusHeight + 'rpx';
			this.$emit('getHeight', systems)
		}
	}
</script>

<style lang="scss" scoped>
	@import url('@/static/css/flex.css');
	.leftIcon{
		width: 172rpx;
		height: 64rpx;
		background: #FFFFFF;
		border-radius: 32rpx;
		// opacity: 0.4;
		border: 2rpx solid #e8e8e8;
		position: absolute;
		left: 30rpx;
		padding:0 30rpx;
		box-sizing: border-box;
	}
	/*正中*/
	.bar-content {
		width: 100%;
		height: auto;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.bar-title {}
	}

	//导航栏吸顶效果
	.bar-sticky {
		position: sticky;
		position: -webkit-sticky;
		top: 0;
		z-index: 101;
	}

	.bar-fixed {
		position: fixed;
		position: -webkit-fixed;
		top: 0;
		width: 100%;
		z-index: 101;
		box-shadow: 0px 0px 0px 0px #D1D1D3;
	}

	/*垂直居中*/
	.container-in {
		display: flex;
		-webkit-align-items: center;
		align-items: center;
		width: 100%;
		height: 44px;
	}

	.bar-line {
		height: 44px; //导航栏高度

		.bar-back {
			font-size: 52rpx !important;
			position: absolute;
			left: 30rpx;
		}

		.bar-title {
			font-size: 32rpx;
		}
	}
</style>
